package com.sky.sky_server.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sky.sky_common.result.Result;

import lombok.extern.slf4j.Slf4j;

@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")
public class ShopController {
    
    private static final String SHOP_KEY = "shop_status";

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    /**
     * 修改店铺状态
     * @param status
     */
    @PutMapping("/{status}")
    public Result updateStatus(@PathVariable Integer status) {
        log.info("修改店铺状态：{}", status == 1 ? "营业中" : "已打烊");
        redisTemplate.opsForValue().set(SHOP_KEY, status);
        return Result.success();
    }

    /**
     * 获取店铺营业状态状态
     * @return
     */
    @GetMapping("/status")
    public Result getShopStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(SHOP_KEY);
        if (status != null) {
            log.info("获取店铺的营业状态为：" + (status == 1 ? "营业中" : "已打烊"));
            return Result.success(status);
        }
        return Result.error("获取店铺状态失败");
    }
}
